//
//  LCTabbarController.m
//  LookCoupons
//
//  Created by 明明方 on 2017/9/8.
//  Copyright © 2017年 明明方. All rights reserved.
//

#import "LCTabbarController.h"
#import "LCTabBar.h"
#import "MainNavigationController.h"
#import "HomeController.h"
@interface LCTabbarController ()<LCTabBarDelegate>
@property(nonatomic, strong) LCTabBar * lctabBar;
@property(nonatomic, strong) NSMutableArray * itemsArr;
@end

@implementation LCTabbarController

- (NSMutableArray *)itemsArr {
    if (!_itemsArr) {
        _itemsArr = [[NSMutableArray alloc] init];
    }
    return _itemsArr;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    for (UIView * subView in self.tabBar.subviews) {
        if (![subView isMemberOfClass:[LCTabBar class]]) {
            [subView removeFromSuperview];
        }
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    for (UIView * subView in self.tabBar.subviews) {
        if (![subView isMemberOfClass:[LCTabBar class]]) {
            [subView removeFromSuperview];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    HomeController * homeVC = [[HomeController alloc] init];
    [self addChildVC:homeVC title:@"首页" selectImage:@"M1" image:@"M11"];
//
//    LCFashionController * fashionVC = [[LCFashionController alloc] init];
//    [self addChildVC:fashionVC title:@"" selectImage:@"时尚(选中)" image:@"时尚(灰色)"];
//
////    LCArticleController * articleVC = [[LCArticleController alloc] init];
//    LCThreeController * shopCartVC = [[LCThreeController alloc] init];
//    [self addChildVC:shopCartVC title:@"" selectImage:@"购物车选中" image:@"购物未选中"];
//
//    LCMineController * mineVC = [[LCMineController alloc] init];
//    mineVC.view.backgroundColor = [UIColor clearColor];
//    [self addChildVC:mineVC title:@"" selectImage:@"我的（选中）" image:@"我的（灰色）"];
    
    [self.tabBar addSubview:self.lctabBar];

}

- (void)addChildVC:(UIViewController *)vc title:(NSString *)title selectImage:(NSString *)selectImageName image:(NSString *)imageName {
    MainNavigationController * navigationVC = [[MainNavigationController alloc] initWithRootViewController:vc];
    navigationVC.tabBarItem.title = title;
    navigationVC.tabBarItem.selectedImage = [UIImage imageNamed:selectImageName];
    navigationVC.tabBarItem.image = [UIImage imageNamed:imageName];
    [self.itemsArr addObject:navigationVC.tabBarItem];
    [self addChildViewController:navigationVC];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

#pragma mark - lzay
- (LCTabBar *)lctabBar {
    if (!_lctabBar) {
        _lctabBar = [[LCTabBar alloc] initWithFrame:self.tabBar.bounds];
        _lctabBar.items = self.itemsArr;
        _lctabBar.delegate = self;
    }
    return _lctabBar;
}

- (void)clickBtn:(NSInteger)tag {
    self.selectedIndex = tag;
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex {
    [super setSelectedIndex:selectedIndex];
    self.lctabBar.selectIndex = selectedIndex;
}





@end
